package com.aop.Propagation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Package: com.aop.Propagation
 * @ClassName: PropagationBehavior
 * @Author: h2cloud
 * @CreateTime: 2023/12/27 11:07 下午
 * @Description:
 */
@Service
public class PropagationBehavior {

	@Autowired
	private PropagationBehavior propagationBehavior;

	// required -> required
	@Transactional(propagation = Propagation.REQUIRED)
	public void requiredMethod1() {
		System.out.println("requiredMethod");
		try {
			propagationBehavior.requiredMethod2();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Transactional(propagation = Propagation.REQUIRED)
	public void requiredMethod2() {
		int i = 1 / 0;
		System.out.println("requiredMethod2");
	}
}
